package com.example.easy.Controller;

import com.example.easy.Dto.User;
import com.example.easy.Service.Impl.UserServiceImpl;
import com.example.easy.Service.Service.UserService;
import com.example.easy.Tools.ResultCode;
import com.example.easy.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Scope("prototype")
@RestController
@Api(value = "User", description = "用户管理")
@RequestMapping(value = "/user")
public class UserContriller {

    @Autowired
    UserService userService;
    @Autowired
    UserMapper userMapper;

    @ApiOperation(value = "注册",notes = "注册")
    @RequestMapping(value = "/userregister", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
     public Object regsiter(@RequestBody User user)throws  IOException{
     return ResultCode.SUCCESS.result(userService.regsiter(user));


    }



    @ApiOperation(value = "登入", notes = "登入")
    @RequestMapping(value = "/userlogin", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object login(@RequestParam String name, @RequestParam String psd) throws IOException {

        return ResultCode.SUCCESS.result(userService.login(name, psd));

    }

    @ApiOperation(value = "修改资料", notes = "修改资料")
    @RequestMapping(value = "/userupdinfo", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object updInfo(@RequestBody User user) throws IOException {

        userService.updInfo(user);
        return ResultCode.SUCCESS.result();

    }

    @ApiOperation(value = "测试", notes = "测试")
    @RequestMapping(value = "/usertest", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object test(@RequestParam String user) throws IOException {


        return ResultCode.SUCCESS.result(userMapper.selectall(user));

    }


}
